<template>
	<view>
		<publicList :list="list" :addpageUrl="'/pages/quickly/information/information'" @detail='detail' @savestate='savestate' @search="search" :options="options" :nullData="nullData" @bindClick="bindClick"></publicList>
		<u-modal v-model="showModal" :show-cancel-button="true" @confirm="Modalconfirm" :content="showContent"></u-modal>
	</view>
</template>

<script>
import publicList from '@/components/publicList/index.vue'	
import {filterData2} from '@/static/js/filter.js'
export default{
	components:{publicList},
	data() {
		return {
			showModal:false,
			showContent:'',
			list: null,
			listLabel:[
				{
					name:'表单编号：',
					key:'sn'
				},
				{
					name:'签发时间：',
					key:'updateTime'
				},
			],
			listtitle:'会员基本信息表',
			options: [{
				text: '删除',
				style: {
					backgroundColor: '#EE2437' // 删除按钮背景  红的
				}
			}],
			page: 1,
			nullData:false,
			deleteList: '',
			SearchuserId:''
		}
	},
	onLoad() {
		this.getlist({pageIndex:1,pageSize:10,userId:this.SearchuserId})
	},
	onReachBottom(){
		if(this.nullData == true){
			return;
		}
		this.page = this.page + 1
		this.getlist({pageSize:10,pageIndex:this.page,name:this.name,userId:this.SearchuserId})
	},
	methods:{
		search(e) {
			this.page = 1
			this.nullData = false
			this.$api.userInfolist({pageSize:10,pageIndex:1,userName:e}).then(res=>{
				var data =  res.data.result && res.data.result.elements.map((a)=>{
					a.updateTime = a.updateTime || ''
					return a
				})
				this.list = data
				if(this.list.length >= res.data.result.totalCount){
					this.nullData = true;
				}
			})
		},
		filterData2,
		getlist(data){
			const _this = this;
			_this.$api.userInfolist(data).then(res=>{
				var data =  res.data.result && res.data.result.elements.map((a)=>{
					a.updateTime = a.updateTime || ''
					return a
				})
				if(_this.deleteList == 1) {
					_this.list = []
					_this.list = data
					_this.deleteList = ''
				}else {
					_this.list = _this.list ? _this.list.concat(data) : data
					if(_this.list.length >= res.data.result.totalCount){
						_this.nullData = true;
					}
				}
				
			})
		},
		bindClick(e){
			this.showModal = true
			this.showContent = '是否删除此会员基本信息记录'
			this.delItem = e
		},
		Modalconfirm(){
			this.$api.UserInfodelete(this.delItem.id).then((res)=>{
				if(res.data.returnCode == 200){
					uni.showToast({
						title:'删除成功',
						icon:'none'
					})
					this.page = 1
					this.deleteList = 1;
					this.nullData = false;
					this.getlist({pageIndex:1,pageSize:10,userId:this.SearchuserId})
				}
			})
		},
		detail(item){
			!item.status || item.status == 1?
				uni.navigateTo({url:'/pages/quickly/information/information?id='+item.id})
			:
				uni.navigateTo({url:'/pages/quickly/information/toView?id='+item.id})
		},
		savestate(e) {
			e.status = 2
			e.geneticHistory = JSON.parse(e.geneticHistory);
			e.familyHistory = JSON.parse(e.familyHistory);
			e.pastHistory = JSON.parse(e.pastHistory)
			this.$api.userinforUpdate(e).then((res) => {
				if(res.data.returnCode =='200') {
					uni.showToast({
						title: '存档成功',
						icon: 'none'						
					})
					this.deleteList = 1;
					setTimeout(() => {
						this.getlist({pageIndex:1,pageSize:10,userId:this.SearchuserId})
					},1000)
				}
			})
		}
	}
}
</script>

<style>
	
</style>
